package com.ankang.art.controller;

import com.ankang.art.pto.HzsReultPto;
import com.ankang.art.service.HzsResultService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/art/management/sts")
@CrossOrigin
public class HzsResultController {

    @Autowired
    HzsResultService hzsResultService;

    @GetMapping("/deletedResult")
    public ResponseEntity deletedResult(@RequestParam(value = "id") Integer id){

        if(null == id){
            throw new RuntimeException("id不能为空");
        }

        hzsResultService.deleteResult(id);

        return new ResponseEntity(HttpStatus.OK);
    }

    @GetMapping("/getResult")
    public ResponseEntity getResult(@RequestParam(value = "studentId" ,required = false) Integer studentId,
                                    @RequestParam(value = "studentName",required = false) String studentName,
                                    @RequestParam(value = "pageNo",defaultValue = "1") Integer pageNo,
                                    @RequestParam(value = "pageSize" ,defaultValue = "10") Integer pageSize){


        PageHelper.startPage(pageNo, pageSize);


        return new ResponseEntity(hzsResultService.getResult(studentId,null),HttpStatus.OK);
    }
    @PostMapping("/updateResult")
    public ResponseEntity updateResult(@RequestBody HzsReultPto hzsReultPto){

        hzsResultService.updateResult(hzsReultPto);

        return new ResponseEntity(HttpStatus.OK);
    }
}
